# Table C2

#####
rm(list=ls(all=TRUE))

library(MASS)
library(stargazer)

#### Dataset Original ####
setwd("/Users/sebastian/Dropbox/The politics of interruptions - JOP RR/Replication Files/Data Rep")
load("data_empirics_rep.Rdata")

### Create Periods ----
data_empirics$pre_1998 <- ifelse(data_empirics$cohort == "1988-1990" |
                                   data_empirics$cohort == "1990-1992" | 
                                   data_empirics$cohort == "1992-1994" | 
                                   data_empirics$cohort == "1994-1996" |
                                   data_empirics$cohort == "1996-1998", 1, 0)

# Before an interruption:----
data_empirics_interruptions <- data_empirics[data_empirics$interruption_final_dummy==1,]  
data_empirics_aggressive <- data_empirics[data_empirics$aggressive_interruption_dummy==1,]  
data_empirics_procedural <- data_empirics[data_empirics$time_interruption_dummy==1,]  

model_3.1 <- glm.nb(length_speech_nocont ~ female_dum + ideology_ext + 
                      committee_chair + seniority + type_member +
                      party_match_pres + 
                      election_year +
                      tot_num_speeches_session_10 + mean_length_leg +
                      negative_lang_w + mujeres_dummy + 
                      factor(cohort), 
                    data = data_empirics_interruptions)

model_3.1_pre1998 <- glm.nb(length_speech_nocont ~ female_dum + ideology_ext + 
                              committee_chair + seniority + type_member +
                              party_match_pres + 
                              election_year +
                              tot_num_speeches_session_10 + mean_length_leg +
                              negative_lang_w + mujeres_dummy + 
                              factor(cohort), 
                            data = subset(data_empirics_interruptions,
                                          data_empirics_interruptions$pre_1998==1))

model_3.1_pre2008post1998 <- glm.nb(length_speech_nocont ~ female_dum + ideology_ext + 
                                      committee_chair + seniority + type_member +
                                      party_match_pres + 
                                      election_year +
                                      tot_num_speeches_session_10 + mean_length_leg +
                                      negative_lang_w + mujeres_dummy +
                                      factor(cohort), 
                                    data = subset(data_empirics_interruptions, data_empirics_interruptions$post_2008==0 &
                                                    data_empirics_interruptions$pre_1998==0))

model_3.1_post2008 <- glm.nb(length_speech_nocont ~ female_dum + ideology_ext + 
                               committee_chair + seniority + type_member +
                               party_match_pres + 
                               election_year +
                               tot_num_speeches_session_10 + mean_length_leg +
                               negative_lang_w + mujeres_dummy +
                               factor(cohort), 
                             data = subset(data_empirics_interruptions, data_empirics_interruptions$post_2008==1))

######  After an interruptions? ----

data_interruption <- data_empirics[data_empirics$interruption_final_dummy==1,]
data_interruption_only <- data_interruption[data_interruption$interruption_final_combined==1,]  
data_interruption_between <- data_interruption[data_interruption$interruption_final_combined==2,]  

model_after_1 <- glm.nb(length_after_interruption ~ female_dum + ideology_ext + 
                          committee_chair + seniority + type_member +
                          party_match_pres + 
                          election_year  + length_speech_nocont_100 +
                          tot_num_speeches_session_10 + mean_length_leg +
                          negative_lang_w + mujeres_dummy +
                          factor(cohort), 
                        data = data_interruption)

model_after_1_pre1998 <- glm.nb(length_after_interruption ~ female_dum + ideology_ext + 
                                  committee_chair + seniority + type_member +
                                  party_match_pres + 
                                  election_year  + length_speech_nocont_100 +
                                  tot_num_speeches_session_10 + mean_length_leg +
                                  negative_lang_w + mujeres_dummy +
                                  factor(cohort), 
                                data = subset(data_interruption,
                                              data_interruption$pre_1998==1))

model_after_1_post1998pre2008 <- glm.nb(length_after_interruption ~ female_dum + ideology_ext + 
                                          committee_chair + seniority + type_member +
                                          party_match_pres + 
                                          election_year  + length_speech_nocont_100 +
                                          tot_num_speeches_session_10 + mean_length_leg +
                                          negative_lang_w + mujeres_dummy +
                                          factor(cohort), 
                                        data = subset(data_interruption,
                                                      data_interruption$pre_1998==0 &
                                                        data_interruption$post_2008==0))

model_after_1_post2008 <- glm.nb(length_after_interruption ~ female_dum + ideology_ext + 
                                   committee_chair + seniority + type_member +
                                   party_match_pres + 
                                   election_year  + length_speech_nocont_100 +
                                   tot_num_speeches_session_10 + mean_length_leg +
                                   negative_lang_w + mujeres_dummy +
                                   factor(cohort), 
                                 data = subset(data_interruption,
                                               data_interruption$post_2008==1))

#### TABLE: Length after and before interruption ####

setwd("/Users/sebastian/Dropbox/The politics of interruptions - JOP RR/Replication Files/Table")

stargazer(model_3.1,model_3.1_pre1998,model_3.1_pre2008post1998,model_3.1_post2008,
          model_after_1, model_after_1_pre1998,model_after_1_post1998pre2008,
          model_after_1_post2008,
          type = "html", style = "ajps", out = "tableC2.html",
          covariate.labels = c("Woman","Ideological Extremism","Committee Chair",
                               "Seniority", "National MC","Same Party as Leg. Pres.",
                               "Election Year", "Length of Speech","Speeches during Session",
                               "Mean Length of MC Speech",
                               "Negative Language (Speech)", "Topic: Women"),
          omit = "factor",
          # se = list(robust_seDEM2,robust_seAUT2,robust_seDEM_PROBIT,robust_seAUT_PROBIT,
          #           robust_seDEM_LOGIT,robust_seAUT_LOGIT),
          no.space=TRUE,
          dep.var.labels=c("Length Before Interruption (All)","Length After Interruption (All)"),
          digits=3,
          df = FALSE,
          keep.stat = c("theta", "n"))
